/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.ui.components;

import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import org.bff.slimserver.exception.SlimConnectionException;

/**
 *
 * @author bfindeisen
 */
public class YearComboBox extends JComboBox {

    private DefaultComboBoxModel yearModel;

    private List<String> yearList;
    
    public static final String ALL_YEARS = "all";
    
    public YearComboBox() {
        yearModel = new DefaultComboBoxModel();
        setModel(yearModel);
        listYears();
    }
    
    private void listYears() {
        yearModel.removeAllElements();
        yearModel.addElement(new String("All"));

        try {
            setYearList(new ArrayList<String>(JukeboxProperties.getInstance().getDatabase().getYears()));
            for(String year : getYearList()) {
            yearModel.addElement(year);
        }
        } catch (SlimConnectionException ex) {
            Logger.getLogger(YearComboBox.class.getName()).log(Level.SEVERE, null, ex);
        }
        setModel(yearModel);
        
    }
    
    /**
     * "All" will be returned for all years
     * @return
     */
    public String getSelectedYear() {
        return (String)getSelectedItem();
    }

    public List<String> getYearList() {
        return yearList;
    }

    public void setYearList(List<String> yearList) {
        yearList.remove("0");
        this.yearList = yearList;

    }
}
